<template>

	<div>
		<u-navbar :autoBack="true" :safeAreaInsetTop="true" :placeholder="true" bgColor="#FFF" :fixed="true">
			<view slot="left" style="display: flex;">
				<u-icon v-if="flag" name="arrow-left" size="28"></u-icon>
				<view
					style=" line-height: 27px; text-align: center; color: #000;width: 100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;margin-left: 20rpx">
					{{ title || '自测记录' }}
				</view>
			</view>
			<!-- <view slot="center">
				<view
					style=" line-height: 27px; text-align: center; color: #000;width: 73%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
					{{ title || '自测记录' }}
				</view>
			</view> -->
			<view slot="right" style="margin-right: 200rpx;position: relative;">
				<image style="width: 46rpx;" src="../../static/images/setUp.svg" mode="" @click="isSetUp = !isSetUp">
				</image>
				<view v-if="isSetUp"
					style="width: 240rpx;padding:20rpx;box-shadow: 0px 0px 9px 0px #0000001A;position: absolute;top: 300rpx;right: -120rpx;background-color: #fff;">
					<view style="flex-direction: row;display: flex;justify-content: space-around;"
						@click="fontModal = true">
						<image style="width: 32rpx;height: 36rpx;" src="../../static/images/font.svg" mode="">
						</image>
						<text style="margin-left: 20rpx; text-align: center;width: 60%;">字号设置</text>
					</view>
					<view style="flex-direction: row;display: flex;margin: 30rpx 0;justify-content: space-around;"
						@click="showCalculator">
						<image style="width: 32rpx;height: 36rpx;" src="../../static/images/calculator.svg" mode="">
						</image>
						<text style="margin-left: 20rpx; text-align: center;width: 62%;">计算器</text>
					</view>
					<view style="flex-direction: row;display: flex;justify-content: space-around;">
						<text>自动换题</text>
						<u-switch v-model="automatic" activeColor="#37B874" size="20"></u-switch>
					</view>
				</view>
			</view>
		</u-navbar>
		<view v-if="examStatus"
			style="text-align: center;margin-top: 10rpx;display: flex;justify-content:center;position:relative;padding-top: 20rpx;background-color: #fff;">
			<view style="display: flex;width: 100%;justify-content: center;align-items: center;">倒计时：<u-count-down
					:time="minute * 60 * 1000" autoStart format="HH:mm:ss" @finish="finish"></u-count-down>
			</view>
			<view v-if="!flag" @click="onSubmitModal" style="position: absolute;right: 40rpx;">
				<text style="color: #37B874;">交卷</text>
			</view>
		</view>
		<view
			:style="{ padding: '30rpx 40rpx 60rpx 40rpx', backgroundColor: '#FFF', height: windowHeight - 200 + 'px', overflow: 'auto', }"
			@click="isSetUp = false" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
			<!-- <text style="background-color: #F6FFF7;border-radius: 20rpx 20rpx 20rpx 0;padding: 6rpx 10rpx;">{{
				onChangeDict(showQuestion.type,
					mapDictCodesData.allQuestionType) }}</text> -->
			<text
				style="border: 1px solid #37B874;border-radius: 20px 20px 20px 0;padding: 5rpx 15rpx;background-color: #F3FBF7;display:inline-block;margin:2px 5px 40rpx 0">{{
					onChangeDict(showQuestion.type,
						mapDictCodesData.allQuestionType) }}</text>
			<view style="border-radius: 10rpx;  padding-top: 10rpx;">
				<view class="questionText"
					:style="{ fontSize: fontSize + 'rpx', lineHeight: (fontSize + 12) + 'rpx', display: 'flex', flexDirection: 'row', overflow: 'auto' }">
					<!-- <view>
						<text>{{ questionsCHildType + 1 }}、</text>
					</view> -->
					<!-- <view style="flex: 1;">
						<rich-text :nodes="showQuestion.itemText"></rich-text>
					</view> -->
					<u-parse :content="showQuestion.itemText" style="text-align: justify"></u-parse>
				</view>


			</view>
			<RadioQuestion v-if="['0101', '0201'].includes(showQuestion.type)" :showQuestion="showQuestion"
				:selectAnswer="selectAnswer" :windowHeight="windowHeight" :fontSize="fontSize" flag="true"
				:showAnalysis="showQuestion.stuAnswer"></RadioQuestion>
			<CheckBoxQuerstion v-else-if="showQuestion.type === '0301'" :showQuestion="showQuestion"
				:selectAnswer="selectAnswer" :windowHeight="windowHeight" :fontSize="fontSize"
				:showAnalysis="showQuestion.stuAnswer" flag="true"></CheckBoxQuerstion>
			<view v-else-if="['si01', 'si02', 'si03', 'si04', 'si06'].includes(showQuestion.type)"
				:style="{ overflow: 'auto', marginTop: '30rpx' }">
				<view class="questionTextItem">
					<u--textarea v-model="selectAnswer" placeholder="请输入答案" autoHeight border="bottom"></u--textarea>
				</view>
			</view>

			<view v-else-if="['案例题', '情景题', '计算分析'].includes(showQuestion.itemTypeName)"
				:style="{ overflow: 'auto', marginTop: '30rpx', marginBottom: '100rpx' }">
				<view>
					<view
						style="width: 100%; flex-direction: row; justify-content: space-between; margin: 0rpx 0rpx 30rpx;">
						<view @click="onAnswerItem('top', true)" class="childText" style="width: 30%;">上一小题</view>
						<view class="childText" style="width: 36%;">
							{{ '当前第' + (childIndex + 1) + '/' + showQuestion.children.length + '小题' }}
						</view>
						<view @click="onAnswerItem('bottom', true)" class="childText" style="width: 30%;">下一小题</view>
					</view>
					<view style="padding: 0rpx 30rpx; border-radius: 10rpx; background-color: #FFF;">
						<view class="questionText"
							:style="{ fontSize: fontSize + 'rpx', lineHeight: (fontSize + 12) + 'rpx', flexDirection: 'row' }">
							<view style="margin-right: 20rpx">
								{{ (childIndex + 1) + ' ) ' }}
							</view>
							<rich-text :nodes="showQuestion.children[childIndex].itemText"></rich-text>
						</view>
					</view>

					<RadioQuestion v-if="['判断题', '单选题'].includes(showQuestion.children[childIndex].itemTypeName)"
						:showQuestion="showQuestion.children[childIndex]" :selectAnswer="selectAnswer"
						:windowHeight="windowHeight" :fontSize="fontSize"></RadioQuestion>
					<CheckBoxQuerstion v-else-if="showQuestion.children[childIndex].itemTypeName === '多选题'"
						:showQuestion="showQuestion.children[childIndex]" :selectAnswer="selectAnswer"
						:windowHeight="windowHeight" :fontSize="fontSize"></CheckBoxQuerstion>
					<view
						v-else-if="['简答题', '填空题', '计算题', '论述题', '绘图题'].includes(showQuestion.children[childIndex].itemTypeName)"
						:style="{ overflow: 'auto', marginTop: '30rpx' }">
						<view class="questionTextItem">
							<u--textarea v-model="selectAnswer" placeholder="请输入答案" autoHeight
								border="bottom"></u--textarea>
						</view>
					</view>
				</view>
			</view>
			<!-- <view v-if="['0101', '0201'].indexOf(showQuestion.type)===-1" @click="onUploadStuAnswer">
				确认答案
			</view> -->
			<view v-if="isRecord  ||(isExhibition && showQuestion.answer && showQuestion.stuAnswer) "
				style="background: linear-gradient(180deg, #FBFFFB 0%, #F6FFF7 100%);border-radius: 12px;display: flex;align-items: center;padding:20rpx 40rpx;margin-top: 40rpx;">
				正确答案：{{ showQuestion.answer }} 您的选择：{{ showQuestion.stuAnswer || '' }}
			</view>
			<!-- <view v-if="(isRecord || isExhibition) && showQuestion.answer && showQuestion.stuAnswer"
				:style="{ padding: '30rpx 40rpx 60rpx 40rpx', backgroundColor: '#F9F9F9', marginTop: '40rpx' }">
				<view>
					<view style="display: flex;align-items: center;">
						<text>试题解析</text>
					</view>
					<view style="font-size: 14px;margin-top: 20rpx;">
						<rich-text :nodes="showQuestion.analysis ? showQuestion.analysis : '暂无'"></rich-text>
					</view>
				</view>

			</view> -->
			<view  v-if="isRecord  ||(isExhibition && showQuestion.answer && showQuestion.stuAnswer) " style="margin-top: 40rpx;">
				<view style="display: flex;align-items: center;">
					<text>试题解析</text>
				</view>
				<view style="font-size: 14px;margin-top: 20rpx;background: #F9F9F9;padding: 40rpx 20rpx;">
					<rich-text :nodes="showQuestion.analysis ? showQuestion.analysis : '暂无'"></rich-text>
				</view>
			</view>
		</view>

		<view
			:style="{ position: 'absolute', height: '120rpx', backgroundColor: ' #fff', bottom: 0, padding: '40rpx', display: 'flex', justifyContent: 'space-around', alignItems: 'center', width: windowWidth - 40 + 'px' }">

			<u-icon name="arrow-left" size="20" @click="onAnswerItem('top', '', true)"></u-icon>
			<view style="display: flex;" @click="showExamCount = true">
				<view style="display: flex;">
					<text class="answered"></text>
					<text style="margin:0 40rpx 0 20rpx;">已答</text>
				</view>
				<view style="display: flex;">
					<text class="unanswered"></text>
					<text style="margin-left: 20rpx;">未答</text>
				</view>
			</view>
			<u-icon name="arrow-right" size="20" @click="onAnswerItem('bottom', '', true)"></u-icon>
			<view class="">{{ questionsCHildType + 1 }}/{{ allData.length }}</view>
		</view>
		<u-popup :show="showExamCount" @close="showExamCount = false" :round="0" mode="bottom">

			<view style="padding: 46rpx">
				<view style="text-align: center;">试题导航</view>
				<view style="display: flex;justify-content: space-between;margin-top: 40rpx;margin-bottom: 60rpx;">


					<view style="display: flex;">
						<view style="display: flex;">
							<!-- <u-icon name="checkmark-circle-fill" size="20" color="#2B5182"></u-icon> -->
							<text class="answered"></text>
							<text style="margin:0 40rpx 0 20rpx;">已答</text>
						</view>
						<view style="display: flex;">

							<text class="unanswered"></text>
							<!-- <u-icon name="close-circle-fill" size="20" color="#FF3D31"></u-icon> -->
							<text style="margin-left: 20rpx;">未答</text>
						</view>
					</view>
					<view class="">{{ questionsCHildType + 1 }}/{{ allData.length }}</view>
				</view>
				<view :style="{ height: windowHeight * 0.4 + 'px', overflow: 'auto' }">
					<u-grid :border="false" col="5">
						<u-grid-item v-for="(item, index) in allData" :key="index">
							<view @click="onSelectQuestion(item, index)"
								:class="item.hasAnswer ? 'answered' : 'unanswered'"
								:style="{ width: '60rpx', height: '60rpx', alignItems: 'center', justifyContent: 'center', borderRadius: '12rpx', color: item.hasAnswer ? '#fff' : '#999999', marginBottom: '16rpx', }">
								{{ index + 1 }}
							</view>
						</u-grid-item>
					</u-grid>

				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
		<!-- <u-modal :show="submitModal" @confirm="onSubmit" :showCancelButton="true" @cancel="submitModal = false;"
			:asyncClose="submitNum === 3">
			<view style="width: 100%; padding: 30rpx;">
				<view
					style="width: 100%; flex-direction: row; justify-content: space-between; align-items: center; margin-bottom: 30rpx;">
					<view v-if="unanswered > 0">练测试题剩余{{ unanswered }}道题未做，是否确认提交</view>
					<view v-else>自测已经答完,是否确认提交</view>

				</view>
			</view>
		</u-modal> -->
		<u-popup :show="submitModal" :round="10" mode="bottom" @close="submitModal = false">
			<view style="padding: 40rpx;align-items: center;text-align: center;">
				<view style="font-size: 18px;">
					温馨提示
				</view>
				<image style="width: 421rpx;height: 320rpx" src="../../static/images/submit.svg"></image>
				<view style="margin-top: 40rpx;">您确认要提交试卷吗？</view>
				<view style="margin-top: 40rpx;font-size: 14px;color: #999999;">
					为防止您误触交卷按钮，交卷时将会有3次确认弹窗,本弹窗为第{{ submitNum }}次弹窗（{{ submitNum }}/3）</view>

				<!-- <view style="display: flex;flex-direction: row;margin-top: 60rpx;padding: 0 10rpx;">
					<u-button color="linear-gradient(180deg, #2B5182 0%, #258FF0 100%)"
						:customStyle="{ marginRight: '30rpx', width: '280rpx' }" @click="onSubmit" type="primary"
						text="确认"></u-button>
					<u-button :customStyle="{ width: '280rpx', transform: 'rotateZ(0deg)' }" type="primary" :plain="true"
						:hairline="true" @click="submitModal = false" text="取消"></u-button>

				</view> -->
				<view style="margin-top: 70rpx;" @click="onSubmit">确认</view>
				<view style="width: 100%;height:10rpx;background-color: #F2F2F2;margin: 30rpx 0;"></view>
				<view @click="onClose">取消</view>
			</view>
		</u-popup>
		<u-popup :show="fontModal" mode="bottom" @close="fontModal = false; isSetUp = false" :round="10" closeable>
			<view style="padding: 40rpx;align-items: center;text-align: center;">
				<view>
					字号设置
				</view>
				<view style="width: 100%;display: flex;align-items: center;">
					<image style="width: 40rpx;height: 40rpx;margin-top: -20rpx;" src="../../static/images/narrow.svg"
						mode="" @click="editFontSize(false)"></image>
					<view style="width: 80%;margin: 60rpx 0;">
						<u-steps :current="current" dot activeColor="#37B874">
							<u-steps-item title="较小"></u-steps-item>
							<u-steps-item title="标准"></u-steps-item>
							<u-steps-item title="中等"></u-steps-item>
							<u-steps-item title="较大"></u-steps-item>
							<u-steps-item title="特大"></u-steps-item>
						</u-steps>
					</view>
					<image style="width: 40rpx;height: 40rpx;margin-top: -20rpx;" src="../../static/images/enlarge.svg"
						mode="" @click="editFontSize(true)"></image>
				</view>
			</view>
		</u-popup>
		<UniPopup type="center" ref="calculator" :maskClick="false" style="z-index: 1000;">
			<view style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: flex-end">
				<view style="width: 90%; height: 72vh">
					<h-calculator @closeCalculatorPopup="showCalculator" />
				</view>
			</view>
		</UniPopup>
		<u-loading-page fontSize="32rpx" :loading="loading" loading-text="正在加载..."></u-loading-page>
	</div>
</template>

<script>
import RadioQuestion from '../common/RadioQuestion.vue'
import CheckBoxQuerstion from '../common/CheckBoxQuerstion.vue'
import {
	notificationFun
} from '../../utils/PrjUtils.js'
import {
	mapDictCodes
} from '../../services/ServerService.js'
import { getArrObjectByProperty } from '../../utils/PrjUtils.js'
import { composePaper, getAnalysisList, getPaper, submitPaper, uploadStuAnswer } from '../../services/PracticeTestingService'
import UniPopup from '../../components/uni-popup/uni-popup.vue'
export default {
	components: {
		RadioQuestion,
		CheckBoxQuerstion,
		UniPopup
	},
	data() {
		return {
			loading: true,
			showExamCount: false,
			answer: '',
			minute: '', // 时间
			answered: 0, //已答
			unanswered: 0, //未答
			nowIndex: 0, // 下标
			seconds: 0,
			successData: {},
			childIndex: 0, // 子题 Index
			questionData: [],
			allCount: 0,
			showCount: 1,
			successCount: 0,
			signCount: 0,
			signData: [], // 标记试题数据
			showQuestion: {}, // 当前展示试题
			showQuestionChild: {}, // 当前展示试题的子题
			titleNumber: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六"],
			selectAnswer: '',
			examVersion: 0,
			fontSize: 38, // 题目字体大小
			windowWidth: '',
			windowHeight: '',
			timer: '',
			socketToken: '',
			submitModal: false,
			submitNum: 1,
			examStatus: false,
			activeSatus: false, // 切屏控制 true时 强制交卷
			showStatus: false,
			questionTypes: [],
			type: '',
			questionNavData: [],
			showAnalysis: false,
			countDownShow: false,
			countDown: 0,
			isHistory: false,
			historyShow: false,

			mapDictCodesData: {},
			questionsType: 0,
			questionsCHildType: 0,
			allData: [],
			uuid: '',
			flag: false,
			outlineAlilityLevelId: 59,
			joinId: '',
			outLineTestId: '',
			type: 11,
			bhCheckUuid: '',
			composePlanId: '',
			version: 1,
			isRecord: false, // 是否是自测
			bhCheckId: '',
			id: '',
			title: '', //标题
			isSetUp: false, // 下拉
			automatic: false, //自动换题
			fontModal: false, // 放大缩小字体状态
			current: 0,
			calculatorShow: false, // 计算器状态
			startX: 0, // 触摸开始的X坐标
			endX: 0, // 触摸结束的X坐标
			isExhibition: false, //组卷是否展示答案
		}
	},
	onLoad(option) {
		console.log(option, 'option')
		this.outLineTestId = option.outLineTestId
		this.id = option.id
		// this.joinId = option.joinId
		// this.outLineTestId = option.outLineTestId
		// this.composePlanId = option.composePlanId
		// this.checkId = option.checkId

		this.onMapDictCodes()
		if (option.flag) {
			this.flag = option.flag
			this.onGetAnalysisList(option.checkId)
		} else if (option.isPaper) {

			// 组卷进来的
			this.bhCheckUuid = option.bhCheckUuid
			this.bhCheckId = option.bhCheckId
			this.minute = option.testTime
			this.loading = false
			this.examStatus = true
			this.title = option.title
			this.isExhibition = JSON.parse(option.isExhibition)
			console.log(this.isExhibition,'isExhibition')
			this.onGetPaper(option.bhCheckUuid)
		} else {
			this.onComposePaper(option.outLineTestId, option.id,)
		}

		uni.getSystemInfo({
			success: (res) => {
				this.windowWidth = res.windowWidth
				this.windowHeight = res.windowHeight
			}
		})
	},
	methods: {
		onMapDictCodes() {
			mapDictCodes('allQuestionType').then(res => {
				this.mapDictCodesData = res
			})
		},
		onChangeDict(val, dict) {
			if (dict) {
				return getArrObjectByProperty(dict, 'value', val)?.label || ''
			}
		},
		// 获取时间 
		onComposePaper(outLineTestId, id) {
			composePaper({ outLineTestId, id }).then(res => {

				this.bhCheckUuid = res.bhCheckUuid
				this.bhCheckId = res.bhCheckId
				this.minute = res.testTime
				this.loading = false
				this.examStatus = true
				this.title = res.name
				this.onGetPaper(res.bhCheckUuid)

			}).catch(err => {
				setTimeout(() => {
					uni.navigateBack({
						delta: 1,//返回层数，2则上上页
					})
				}, 2000)

			})
		},
		showCalculator() { // 计算器
			if (!this.calculatorShow) {
				this.calculatorShow = true
				this.$refs.calculator.open();
			} else {
				this.isSetUp = false
				this.calculatorShow = false
				this.$refs.calculator.close();
			}
		},
		onGetAnalysisList(checkId) {
			getAnalysisList({ checkId }).then(res => {
				this.isRecord = true

				this.allData = res
				this.loading = false
				this.showQuestion = res[this.questionsCHildType]
				this.selectAnswer = this.showQuestion.stuAnswer
			})

		},

		// 获取试题
		onGetPaper(bhCheckUuid) {
			getPaper({ bhCheckUuid ,resourceId:this.id}).then(res => {
				this.isRecord = false
				res.forEach((item, index) => {
					// `<text style="border: 1px solid #37B874;border-radius: 20px 20px 20px 0;padding: 5rpx 15rpx;background-color: #F3FBF7;display:inline-block;margin:2px 5px 0 0">${this.onChangeDict(item.type, this.mapDictCodesData.allQuestionType)}</text><text style="height: fit-content;">${index + 1}、</text>`
					item.itemText = `<text style="height: fit-content;">${index + 1}、</text>` + item.itemText
				})
				this.allData = res
				this.showQuestion = res[this.questionsCHildType]
			})
		},
		// 字体放大缩小
		editFontSize(type) {
			if (type) {
				if (this.current < 4) {
					this.current++
					this.fontSize = (this.fontSize + 4) >= 52 ? 52 : (this.fontSize + 4)
				}

			} else {
				if (this.current > 0) {
					this.current--
					this.fontSize = (this.fontSize - 4) <= 20 ? 20 : (this.fontSize - 4)
				}

			}
		},
		onQueryQuestionOnExerciseNavigation(dontShow) {
			this.showExamCount = !dontShow
		},
		onUploadStuAnswer() {
			console.log(this.questionsCHildType, 'this.questionsCHildType')
			this.showQuestion.answer = this.selectAnswer
			this.allData[this.questionsCHildType].hasAnswer = this.selectAnswer
			// this.selectAnswer = this.allData[this.questionsType].items.stuAnswer[this.questionsCHildType]
			uploadStuAnswer({ checkItemId: this.allData[this.questionsCHildType].id, answer: this.selectAnswer }).then(res => {
				console.log('22222');
				this.allData.forEach(item => {
					if (item.id === res.bhCheckItemId) {
						item.answer = res.answer
						item.stuAnswer = res.stuAnswer
					}
				})
				if (this.questionsCHildType + 1 >= this.allData.length) {
					this.countDownShow = false
					// this.allData[this.questionsCHildType].itemText = `<text style="background-color: #F6FFF7; height: fit-content; float: left; border-radius: 20rpx 20rpx 20rpx 0;">${this.onChangeDict(this.allData[this.questionsCHildType].type, this.mapDictCodesData.allQuestionType)}</text><text style="float: left;height: fit-content;">${this.questionsCHildType + 1}、</text>` + res.itemText
					// this.showQuestion = this.allData[this.questionsCHildType]
					// this.showQuestion =
					// 	this.answered = this.allData.filter(item => item.hasAnswer).length
					// this.unanswered = this.allData.filter(item => !item.hasAnswer).length
					notificationFun('已经是最后一题了！')
				} else {
					this.countDownShow = true
					console.log('1111111111');
					this.allData.forEach(item => {
						if (item.id === res.bhCheckItemId) {
							item.answer = res.answer
							item.stuAnswer = res.stuAnswer
						}
					})
					if (this.automatic) {
						setTimeout(() => {
							this.selectAnswer = ''
							this.questionsCHildType += 1
							// this.allData[this.questionsCHildType].itemText = `<text style="background-color: #F6FFF7; height: fit-content; float: left; border-radius: 20rpx 20rpx 20rpx 0;">${this.onChangeDict(this.allData[this.questionsCHildType].type, this.mapDictCodesData.allQuestionType)}</text><text style="float: left;height: fit-content;">${this.questionsCHildType}、</text>` + res.itemText
							this.showQuestion = this.allData[this.questionsCHildType]
							this.selectAnswer = this.showQuestion.hasAnswer || ''
							console.log(this.showQuestion, 'this.showQuestionthis.showQuestion', this.questionsCHildType)
							this.answered = this.allData.filter(item => item.hasAnswer).length
							this.unanswered = this.allData.filter(item => !item.hasAnswer).length
						}, 600)
					}


				}
			})
		},
		onCanSubmit() {
			// this.submitNum = 1;
			this.submitModal = true
		},
		onSubmitModal() {
			this.submitModal = true
		},

		touchStart(event) {
			this.startX = event.touches[0].clientX;
		},
		touchMove(event) {
			// 移动时不做处理
		},
		touchEnd(event) {
			this.endX = event.changedTouches[0].clientX;
			if (this.endX - this.startX > 50) { // 右滑
				// this.currentQuestion = (this.currentQuestion + 1) % this.questions.length;
				console.log('右滑');

				this.onAnswerItem('top', '', true)

			} else if (this.startX - this.endX > 50) { // 左滑
				// this.currentQuestion = (this.currentQuestion - 1 + this.questions.length) % this.questions.length;
				console.log('左滑');
				this.onAnswerItem('bottom', '', true)
			}
		},
		onSubmit() {
			// 交卷

			if (this.submitNum < 3) {
				this.submitModal = false
				setTimeout(() => {
					this.submitNum = this.submitNum + 1
					this.submitModal = true
				}, 600)
			} else {

				this.onSubmitPaper()
			}

		},
		onClose() {
			this.submitModal = false
			this.submitNum = 1
		},
		finish() {
			notificationFun('测评时间结束，您即将被强制交卷！')
			setTimeout(() => {
				this.onSubmitPaper()
			}, 600)
		},
		onSubmitPaper() {
			let stuAnswer = []
			for (let i = 0; i < this.allData.length; i++) {
				if (this.allData[i].hasAnswer) {
					stuAnswer.push({
						itemUuid: this.allData[i].uuid,
						stuAnswer: this.allData[i].hasAnswer,
						version: this.allData[i].version
					})
				}
				// 	else if (this.allData[i].children) {
				// 		for (let c = 0; c < this.allData[i].children.length; c++) {
				// 			stuAnswer.push({
				// 				itemUuid: this.allData[i].children[c].uuid,
				// 				stuAnswer: this.allData[i].children[c].hasAnswer,
				// 				version: this.allData[i].children[c].version
				// 			})

				// 		}
				// 	}
			}
			submitPaper({ checkUuid: this.bhCheckUuid }).then(res => {
				this.submitModal = false
				uni.navigateTo({
					url: '/pages/practiceTesting/completePage?fraction=' + res.score
				})
			})

		},
		onSelectQuestion(item, index) {
			// this.onGetItem(item.itemNo)
			this.questionsCHildType = index
			this.showQuestion = this.allData[this.questionsCHildType]
			this.selectAnswer = this.showQuestion.hasAnswer ? this.showQuestion.hasAnswer : ''
			this.showExamCount = false
			// this.questionNavData[this.questionsCHildType].answer = this.selectAnswer
		},
		onShowAnalysis(isChild) {
			if (this.selectAnswer) {
				getPtAnswer(!isChild ? this.showQuestion.practiceItemUuid : this.showQuestion.children[this.childIndex]
					.practiceItemUuid, this.selectAnswer,).then(res => {
						console.log(res, '答题返回数据');
						this.showQuestion = {
							...this.showQuestion,
							...res
						}
					})
			} else {
				return notificationFun('请选择答案后查看试题解析')
			}
			this.showAnalysis = true
			this.countDownShow = true

			setTimeout(() => {
				if (this.selectAnswer && this.showAnalysis) {
					console.log(isChild, 'isChild')
					this.onAnswerItem('bottom', isChild)
				}
			}, 600)


		},
		onAnswerItem(type, isChild) { // 上下题

			let nowIndex = this.questionsCHildType // 当前大题Index
			let nowChildIndex = this.childIndex // 当前小题Index
			let newIndex
			let newChildIndex

			let isLast = false

			if (type === 'bottom' && !isChild) { // 下一题 大题
				if ((nowIndex + 1) >= this.allData.length) {
					isLast = true
				} else {

					this.questionsCHildType = nowIndex + 1
					console.log(this.questionsCHildType, 'console.log(this.questionsCHildType)')
					this.showQuestion = this.allData[this.questionsCHildType]

					// newIndex = nowIndex + 1
					newChildIndex = 0
				}

			} else if (type === 'top' && !isChild) { // 上一题 大题
				if ((nowIndex) < 1) {
					return notificationFun('已经是第一题了！')
				}

				this.questionsCHildType = nowIndex - 1
				this.showQuestion = this.allData[this.questionsCHildType]

				console.log(this.showQuestion, 'showQuestion')
				newChildIndex = 0
			} else if (type === 'bottom' && isChild) {
				if ((nowChildIndex) > this.allData.length) {
					isLast = true
				}
				newChildIndex = nowChildIndex + 1
				this.questionsCHildType = nowIndex + 1
				this.showQuestion = this.allData[this.questionsCHildType]
			} else if (type === 'top' && isChild) {
				if ((nowChildIndex) < 0) {
					return notificationFun('已经是第一题了！')
				}
				newChildIndex = nowChildIndex - 1
			}

			if (isLast) {
				return notificationFun('已经是最后一题了！')
			} else {
				this.childIndex = newChildIndex
				if (this.allData[this.questionsCHildType].hasAnswer) {
					if (this.isRecord) {
						this.selectAnswer = this.showQuestion.stuAnswer
					} else {
						this.selectAnswer = this.allData[this.questionsCHildType].hasAnswer
					}

					// this.showAnalysis = true 
				} else {
					this.selectAnswer = ''
				}
			}
		},

		checkboxQuest(code) {
			let selectData = this.selectAnswer ? this.selectAnswer.split(',') : []
			if (this.selectAnswer.indexOf(code) !== -1) {
				let newArr = []
				selectData.map(item => {
					if (item !== code) {
						newArr.push(item)
					}
				})
				this.selectAnswer = newArr.sort().toString()
			} else {
				selectData.push(code)
				this.selectAnswer = selectData.sort().toString()
			}
			console.log(this.selectAnswer)
		},
		onChange(data) {
			if (this.isRecord) {
				return
			}
			this.version += 1
			this.selectAnswer = data
			this.allData[this.questionsCHildType].hasAnswer = data
			this.allData[this.questionsCHildType].version = this.version
			console.log(this.allData, 'this.allData')
			this.onUploadStuAnswer()
		},

		onDeleteQuestionWrongItem() {
			deleteQuestionWrongItem(this.showQuestion.studentPracticeItemUUID).then(res => {
				this.onQueryQuestionOnExerciseNavigation(true)
				this.onGetItem(this.showQuestion.itemNo)
			})
		},



	}
}
</script>

<style>
.answered {
	width: 40rpx;
	height: 40rpx;
	border: 2rpx solid #CCC;
	text-align: center;
	line-height: 40rpx;
	display: flex;
	align-items: center;
	background-color: #37B874;
}

.unanswered {
	width: 40rpx;
	height: 40rpx;
	border: 2rpx solid #CCC;
	line-height: 40rpx;
	display: flex;
	align-items: center;
}

.questionTextItem {
	/* padding: 26rpx 50rpx; */
	font-weight: 400;
	font-size: 30rpx;
	line-height: 42rpx;
	color: #232A50;
	background: #FFF;
	border-radius: 10rpx;
	box-sizing: border-box;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	transition: all .3s;
}

.bottomButton {
	flex: 1;
	display: flex;
	text-align: center;
	padding: 10rpx 0;
	color: #3F87FF;
	font-size: 30rpx;
	line-height: 42rpx;
	justify-content: center;
	align-items: center;
}

.u-steps-item__line {
	width: 66rpx !important;
	left: 80rpx !important;
}
</style>